<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

error_reporting(E_ALL);
include_once('../controller/includes/db_access.php');

function transforme_HTML($chaine, $longueur = null) {
// Aide à empêcher les attaques XSS
// Supression des espaces inutiles.
    $chaine = trim($chaine);
// Empêche des problèmes potentiels avec le codec Unicode.
    $chaine = utf8_decode($chaine);
// HTMLise les caractères spécifiques à HTML.
    $chaine = htmlentities($chaine, ENT_NOQUOTES);
    $chaine = str_replace("#", "&#35;", $chaine);
    $chaine = str_replace("%", "&#37;", $chaine);
    $longueur = intval($longueur);
    if ($longueur > 0) {
        
        $chaine = substr($chaine, 0, $longueur);
    
        
    }
    return $chaine;
}



if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'multiple') {

    $dienst = transforme_HTML($_POST['naam']);
    $descr = transforme_HTML($_POST['descr']);
    $vp = ($_POST['vp']);
    $prijs = transforme_HTML($_POST['prijs']);
    $tp = ($_POST['tp']);
    $hvd =($_POST['hvd']);
    $aktief =($_POST['aktief']);


// Insert a new user into the `user` table  
    $q = new Query;
    $q
            ->insert_into('`diensten`', array(
                '`naam`' => $dienst,
                 '`descr`' => $descr,
                '`eenxdienst`' => $vp,
                 '`prijs`' => $prijs,
                '`altijd_toepassen`' => $tp,
                 '`aantal_per_dag`' => $hvd,
                 '`aktief`' => $aktief
                    )
    );

    $result = $q->run();
    $categorie_id = $q->get_insert_id();
    if ($result && $categorie_id > 0) {

        //$Error = '<font color="green">successful : categorie is toegevoed</font>';
               header('Location: dienst_list.php');
    } else {

        $Error = '<font color="red">Error: Dienst is niet toegevoed</font>';
  
           
    }
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!--[if lt IE 9]>
<script
src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" href="styles/style.css" type="text/css" />
<!--[if lte IE 7]>
<link rel="stylesheet" href="style_ie.css" />
<![endif]-->
<title>dbme!!!!</title>
</head>
<body>
<div id="bloc_page">
<header>
 <a href="#"><img src="../images/dBmelogo.png" alt="referentie" alt="dbme!" /></a>
</header>  
 <nav>
    <?php include_once('header.php'); ?>
</nav>
 <section>
  <aside>
  <!--right side baar -->  
  </aside>
     
  <article>  
<table border="0" cellspacing="5" cellpadding="5">

        <tbody>
        <form name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
        <input type="hidden" name="action" value="multiple" />  
            <tr>
                <td colspan="2"><h1>Dienst add</h1><br/><br/>
                <?php if(isset($Error)){
                        echo $Error;
                    }?></td>
            </tr>
            <tr>
                <td valign="top">Dienst naam:
                </td>
                <td valign="top">
                    <input type="text" name="naam" value="" size="20" required="required" />
                   
                </td>
            </tr>
            <tr>
                <td valign="top">Beschrijving:<br />
                
                </td>
                <td valign="top">
                    <TEXTAREA NAME="descr" COLS=40 ROWS=6></textarea>
                   
                </td>
            </tr>
            <tr>
                <td valign="top" colspan="2">
                <input type="radio" name="vp" value="Y" required="required" /> Deze dienst 1 x per verhuur periode berekenen (bijv op/afbouw, alleen eerste en laaste dag) <br />
                <input type="radio" name="vp" value="N" /> Deze dienst elke dag van de verhuur periode berekenen (bijv technicus)
                </td>
            </tr>
             <tr>
                 <td valign="top">Prijs&nbsp;(incl. BTW):
                </td>
                <td valign="top">
                    
                    <input type="number" name="prijs" value="" size="4" required="required"  />
                   
                </td>
            </tr>
             <tr>
                <td valign="top" colspan="2">
                <input type="radio" name="tp" value="N" required="required" /> Deze dienst is naar keuze van klant wel/niet af te nemen.<br />
                <input type="radio" name="tp" value="Y" /> Deze dienst wordt standaard toegepast op elke offerte.
                </td>
            </tr>
                 
             <tr>
                 
                <td valign="top"  colspan="2">Hoe vaak per dag kunt u deze dienst maximaal leveren?<input type="number" name="hvd" value="" size="20" required="required" />
                </td>
       
             
            </tr>
            <tr>
                <td valign="top">Aktief 
                                                                                    
             </td>
            <td valign="top">
                    <input name="aktief" type="radio" value="Y"  /> Ja &nbsp;&nbsp;&nbsp;&nbsp;
                     <input name="aktief" type="radio" value="N" /> Nee
                                                                                    
             </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="save" name="save" />
                  </td>
            </tr>
          </form></tbody>
</table>
          </article>
 
    <aside>
  <!--right side baar -->
       
        
   </aside>
</section>
 
 <footer>  
<p>Lorem ipsum dolor sit amet...</p>
<p>Vivamus sed libero nec mauris pulvinar facilisis ut non sem...</p>
<p>Phasellus ligula massa, congue ac vulputate non, dignissim at augue...</p>
</footer>
</div>
</body>
</html>
